# -*- coding: UTF8 -*-
# Author: Sakurazaki
# (Aitor Martin. @arienai_ne - sakurazaki.setsunita@gmail.com)

import pygame
from pygame.locals import *

import config as c
from config import config
import gamestatemachine as gsm

class SCSG(object):

    def __init__(self):

        c.load_config()

        self.keep = True

        pygame.init()
        pygame.display.init()
        pygame.font.init()

        self.screen = pygame.display.set_mode((config['SCREEN_WIDTH'], config['SCREEN_HEIGHT']))
        pygame.display.set_caption("SCSG v0.0.1a")
        self.clock = pygame.time.Clock()
        self.FPS = config['MAX_FPS']

        self.gsm = gsm.GameStateMachine()

    def run(self):
        
        delta = self.clock.tick(self.FPS)

        while self.gsm.keep and self.keep:

            for event in pygame.event.get():

                if event.type == QUIT:
                    self.keep = False

                self.gsm.handleEvent(event)

            self.gsm.update(delta)

            self.screen.fill(pygame.Color('Black'))

            self.gsm.render(self.screen)
            
            pygame.display.flip()

            delta = self.clock.tick(self.FPS)

        self.quit()

    def quit(self):

        pygame.display.quit()
        pygame.font.quit()
        pygame.quit()

if __name__ == '__main__':

    scsg = SCSG()
    scsg.run()
